package controller

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
	"ginweb/system"
	log "github.com/sirupsen/logrus"
)

type Test struct {
	gorm.Model
	Name string
	Value string
}

func Index(c *gin.Context)  {
	db, err := gorm.Open("mysql", system.GetConfiguration().DSN)
	if err != nil {
		log.Error("mysql连接失败：", err)
	}
	defer db.Close()
	db.AutoMigrate(&Test{})

	////创建
	//insert := Test{Name:"我是测试的name", Value:"我是测试的value"}
	//db.Create(&insert)
	//print(db.NewRecord(insert))

	//查询
	var test Test
	data := db.First(&test, "id=1")
	c.JSON(http.StatusOK,data)
}